package com.sso.controller;

import com.sso.domain.User;
import com.sso.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/login",method = RequestMethod.GET)
    public String loginJsp() {
        return "login";
    }

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public String login(User user) {
        String jwt = userService.login(user);
        if (jwt == null) {
            // 登录失败
            return "redirect:/login";
        }
        return "redirect:http://localhost:8085/prize?jwt="+jwt;
    }

}
